﻿using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using System;

namespace DX.DbStorage.EF
{
    public class UserNameGenerator : ValueGenerator<string>
    {
        public override bool GeneratesTemporaryValues => false;

        public override string Next(EntityEntry entry)
        {
            var provider = entry.Context.GetService<ICurrentUserProvider>();
            if (provider != null)
            {
                return provider.GetName();
            }
            return AppDomain.CurrentDomain.FriendlyName;
        }
    }


}
